<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/6/15
 * Time: 14:57
 */

namespace Weixin\Service;


use Common\Common\Service;
use Weixin\Component\Weixin\WeixinComponent;
use Weixin\Exception\WeixinException;
use Weixin\Request\Weixin\IsWeixinExistRequest;
use Weixin\Response\IsWeixinExistResponse;

class IsWeixinExistService implements Service
{
    public function run(IsWeixinExistRequest $request = null)
    {
        if ($request->issetOpenid() == false) {
            throw new WeixinException(10001);
        }

        $openid = $request->getOpenid();
        $response = new IsWeixinExistResponse();
        $component = new WeixinComponent();
        try {
            $result = $component->isWeixinExist($openid);
            if (is_null($result) == true) {
                $response->setItIsNull();
            }
        } catch (WeixinException $e) {
            throw new WeixinException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}